package com.ruoyi.web.controller.mdm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mdm.domain.SkuProductMasterSub;
import com.ruoyi.mdm.service.ISkuProductMasterSubService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * spu子Controller
 *
 * @author shiseido
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/mdm/skuProductMasterSub")
public class SkuProductMasterSubController extends BaseController {
    @Autowired
    private ISkuProductMasterSubService skuProductMasterSubService;

    /**
     * 查询spu子列表
     */
    @ApiOperation("查询spu关联列表")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkuProductMasterSub skuProductMasterSub) {
        startPage();
        List<SkuProductMasterSub> list = skuProductMasterSubService.selectSkuProductMasterSubList(skuProductMasterSub);
        return getDataTable(list);
    }

    /**
     * 导出spu子列表
     */
    @ApiOperation("导出spu关联列表")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:export')")
    @Log(title = "SPU关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuProductMasterSub skuProductMasterSub) {
        List<SkuProductMasterSub> list = skuProductMasterSubService.selectSkuProductMasterSubList(skuProductMasterSub);
        ExcelUtil<SkuProductMasterSub> util = new ExcelUtil<SkuProductMasterSub>(SkuProductMasterSub.class);
        util.exportExcel(response, list, "spu子数据");
    }

    /**
     * 获取spu子详细信息
     */
    @ApiOperation("获取spu关联详细信息")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(skuProductMasterSubService.selectSkuProductMasterSubById(id));
    }

    /**
     * 新增spu子
     */
    @ApiOperation("新增spu关联")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:add')")
    @Log(title = "SPU关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuProductMasterSub skuProductMasterSub) {
        return toAjax(skuProductMasterSubService.insertSkuProductMasterSub(skuProductMasterSub));
    }

    /**
     * 修改spu子
     */
    @ApiOperation("修改spu关联")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:edit')")
    @Log(title = "SPU关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuProductMasterSub skuProductMasterSub) {
        return toAjax(skuProductMasterSubService.updateSkuProductMasterSub(skuProductMasterSub));
    }

    /**
     * 删除spu子
     */
    @ApiOperation("删除spu关联")
    @PreAuthorize("@ss.hasPermi('mdm:skuProductMasterSub:remove')")
    @Log(title = "SPU关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(skuProductMasterSubService.deleteSkuProductMasterSubByIds(ids));
    }
}
